Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Command Button Animation-2

Introduction.

A screen with animated text or controls adds a lively, dynamic touch to an application, making it more engaging for both the user and the observer. The Command Button Animation article was the very first post I published on this website.

Another enhancement to screen design was the introduction of 3D headings for forms and reports, using a combination of different fonts, sizes, and styles. Initially, these headings were created manually, which eventually led to the development of the 3D Text Wizards.

You can find the details of 3D Text Styles in the following posts.

  1. Create 3D Headings on Forms
  2. Border 2D Heading Text
  3. Border 3D Heading
  4. Shadow 3D Heading Style

The IBM AS/400 (iSeries) screens inspired me to design MS Access interfaces with a dark background, light-shaded data labels, and green text. Although those old text-based screens may seem dated, their clear and highly legible presentation of information remains their greatest strength.

However, when I began designing Access forms in this style, I faced a challenge: the Command Button Animation I had been using wasn’t built for dark backgrounds. This led me to develop a new animation technique—one that complemented the darker design while remaining simple to create and easy to implement without complicated VBA code.

So, here it is for you. I hope you’ll enjoy it as much as I do. We’ll first explore a simple, easy-to-understand version of this method and then move on to a more versatile, reusable routine that can drive the animation on any form with just one or two lines of code.

Command Button Design.

  1. Open a new Form or an existing one.

  2. Select the Footer of the Form. If it is not visible, select Form Header/Footer from the View Menu.

  3. Display the Property Sheet (View -> Properties).

  4. Change the Back Color Property Value to 0.

  5. Select the Command Button Tool from the Toolbox and draw a Command Button in the Footer Section of the Form.

  6. Display the Property Sheet of the Command Button.

  7. Change the Name Property Value to cmdExit and the Caption Property Value to Exit.

  8. Select the Rectangle Tool from the Toolbox and draw a rectangle around the Command Button as shown in the sample design below:

  9. Give a little more gap, between the button and the rectangle at the bottom and the right side than above and left, giving it a feel that the Command Button is in a raised state.

  10. Click on the Rectangle and display its Property Sheet.

  11. Change the Name Property Value to ExitBox and the Visible Property Value to No.

    Animating the Command Button

    Now, it is time to implement the animation trick. This time, we will not animate the button like we did earlier on the Command Button Animation; instead, the Box around it will be made visible or hidden based on the Mouse movement over the Command Button.

    We will track the mouse movement in Code. When the mouse is over the Command Button, the rectangle becomes visible, and when the mouse moves out, it is hidden. When this action is repeated, it will appear as if the command button rises and then returns to its original position. It has a better look and feel in a dark background, rather than remaining flat all the time.

    We need to track the Mouse movement at two positions: the On Mouse Move Event of the Command Button and the On Mouse Move Event in the Form Section.

  12. Select the Command Button.

  13. Display the Property Sheet of the Command Button (View -> Properties).

  14. Select [Event Procedure] in the On Mouse Move property and click on the build button (...).

  15. Copy and paste the code given below between the sub-routine skeleton. You can ignore the first and last lines while copying, as these will be present in the Module.

    Private Sub cmdExit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
         If Me.ExitBox.Visible = False Then
               Me.ExitBox.Visible = True
         End If
    End Sub
    
  16. Click anywhere within the Form Footer to select that area, display the Property Sheet, and repeat Step 14 above.

  17. Copy and paste the following code into the empty skeleton of the sub-routine, as you did above:

    Private Sub FormFooter_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If Me.ExitBox.Visible = True Then
          Me.ExitBox.Visible = False
       End If
    End Sub
    

    Actually, the IF... The statement is not required in the routine. This is introduced to avoid changing the value repeatedly during mouse movements and to avoid flickering.

    Trial Run of Animation

  18. Save the Form and open it in Normal view.

  19. Move the Mouse over and out of the Command Button repeatedly, which will give the button a sense of up and down movement every time.

    The AnimateFrame() Function

    When we implement this animation for several Command Buttons, duplicating the above code everywhere is not good programming. A common routine that can be called with a one-line code, so that it is easy to implement anywhere and for any number of buttons.

  20. Copy and paste the code given below into a Global Module of your database and save it.

Public Function AnimateFrame(ByVal OnOff As Boolean, ByVal x_Box As String)
Dim frm As Form, ctrl As Control
On Error GoTo AnimateFrame_Err

Set frm = Application.Screen.ActiveForm
Set ctrl = frm.Controls(x_Box)

Select Case OnOff
    Case False
        If ctrl.Visible = False Then Exit Function
             frm.Controls(x_Box).Visible = False
    Case True
        If ctrl.Visible = True Then Exit Function 
        frm.Controls(x_Box).Visible = True
End Select

AnimateFrame_Exit:
Exit Function

AnimateFrame_Err:
Resume AnimateFrame_Exit
End Function

Now, we can replace the code we have written earlier with a single-line Code to display and hide the rectangle.

If Me.ExitBox.Visible = False Then

    Me.ExitBox.Visible = True

End If

The above code can be replaced with the statement

AnimateFrame True, "ExitBox"

in the On Mouse Move of the Command Button and

If Me.ExitBox.Visible = True Then
    Me.ExitBox.Visible = False

End If

can be replaced with the statement

AnimateFrame False, "ExitBox"

in the FormFooter_MouseMove event procedure.

  1. Command Button Animation
  2. Double Action Command Button
  3. Colorful Command Buttons
  4. Transparent Command Button
  5. Command Button Animation-2
  6. Creating an Animated Command Button with VBA
  7. Command Button Color Change on Mouse Move

Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code